package com.homelock.controller;

import com.pi.base.dto.result.AppResult;
import com.pi.uc.dao.entity.UcUserEntity;
import org.springframework.util.Assert;
import com.homelock.service.UserEmergencyService;
import com.pi.http.base.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 紧急联系人Controller
 */
@RequestMapping("/user/emergency")
@RestController
public class UserEmergencyController extends BaseController {

    private UserEmergencyService userEmergencyService;

    public UserEmergencyController(UserEmergencyService userEmergencyService){
        Assert.notNull(userEmergencyService, "紧急联系人服务为空");
        this.userEmergencyService = userEmergencyService;
    }

    /**
     * 更新紧急联系人
     * @param name
     * @param phone
     * @return
     */
    @RequestMapping("/update")
    public AppResult update(String name,String phone){
        UcUserEntity ucUserEntity =  this.getLoginUserInfo();
        userEmergencyService.addOrUpdate(this.getLoginUserId(),name,phone);
        return AppResult.OK;
    }

    @RequestMapping("/info")
    public AppResult info(){
        return AppResult.newSuccessResult(userEmergencyService.voInfo(this.getLoginUserId()));
    }

}
